const initState = {
  authToken: null,
  authRole: null,
};
export const authR = (state = initState, action) => {
  switch (action.type) {
    case "REGISTER":
      console.log(action.payload.token);
      return {
        ...state,
        authToken: action.payload.token,
        authRole: action.payload.role,
      };
    case "SIGNIN":
      return {
        ...state,
        authToken: action.payload.token,
        authRole: action.payload.role,
      };
    case "SIGNOUT":
      return {
        ...state,
        authToken: null,
        authRole: null,
        errorMessage: null,
      };
    case "add_error":
      return {
        ...state,
        errorMessage: action.payload,
      };
    default:
      return state;
  }
};

export const statusValue = (state = "user", action) => {
  switch (action.type) {
    case "CHANGESTATE":
      return action.payload;
    default:
      return state;
  }
};
